﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcelToApi
{
    class ExcelToApiClass
    {
        private string mExcelsPath = @"Excels";
        private string mApiPath = @"Apis";

        private ApiGenerator mApiGenerator = new ApiGenerator();

        public void ExportExcel()
        {
            FileSystemInfo[] filesArray = Util.GetAllFileByPath(mExcelsPath);
            if (filesArray != null && filesArray.Length > 0)
            {
                Util.DeleteAllFilesByPath(mApiPath);

                foreach (FileSystemInfo fileSystemInfo in filesArray)
                {
                    if (!fileSystemInfo.Name.Contains("~"))
                    {
                        if (!Util.FileIsOpen(fileSystemInfo.FullName))
                        {
                            Console.WriteLine(string.Format("{0}打开中，配置生成失败！！！", fileSystemInfo.Name));
                            return;
                        }

                        Console.WriteLine(fileSystemInfo.FullName);
                        mApiGenerator.GenerateScript(fileSystemInfo, mApiPath);
                    }
                }

                Console.WriteLine("Api导出成功");
            }
        }
    }
}
